package ${basePackage}.application.service.${modelNameLowerCamel};

import ${basePackage}.application.dto.EmptyDTO;
import ${basePackage}.application.dto.${modelNameLowerCamel}.GetResultDTO;
import ${basePackage}.application.seek.IService;
import ${basePackage}.application.seek.ServiceAbstract;
import ${basePackage}.domain.${modelNameLowerCamel}.I${modelNameUpperCamel};
import ${basePackage}.domain.${modelNameLowerCamel}.I${modelNameUpperCamel}Repository;
import ${basePackage}.domain.seek.IUnitOfWork;
import ${basePackage}.infrastructure.${modelNameLowerCamel}.${modelNameUpperCamel}Repository;
import org.apache.commons.beanutils.BeanUtils;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by ${author} on ${date}.
 * 描述: 查询所有${modelName}的业务对象
 */

public class ListService extends ServiceAbstract<EmptyDTO, List<GetResultDTO>> implements IService<List<GetResultDTO>> {

    /**
     * ${modelName}的仓储对象
     */
    private I${modelNameUpperCamel}Repository i${modelNameUpperCamel}Repository;

    /**
     * 有参构造，获取传入空参数
     *
     * @param emptyDTO 空参数
     */
    public ListService(EmptyDTO emptyDTO) {
        super(emptyDTO);
    }

    /**
     * 查询所有${modelName}信息
     *
     * @return ${modelName}的list集合
     */
    @Override
    public List<GetResultDTO> process() {
        try {
            i${modelNameUpperCamel}Repository = new ${modelNameUpperCamel}Repository(iUnitOfWork);
            List<I${modelNameUpperCamel}> query = i${modelNameUpperCamel}Repository.query();
            List<GetResultDTO> getResultDTOList = new ArrayList<>();
            if (query != null && query.size() > 0) {
                for (I${modelNameUpperCamel} i${modelNameUpperCamel} : query) {
                    GetResultDTO getResultDTO = new GetResultDTO();
                    //实体转dto
                    try {
                        BeanUtils.copyProperties(getResultDTO, i${modelNameUpperCamel});
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    } catch (InvocationTargetException e) {
                        e.printStackTrace();
                    }
                    getResultDTOList.add(getResultDTO);
                }
            }
            return getResultDTOList;
        } finally {
            iUnitOfWork.close();
        }
    }
}
